package com.bwf.pojo;

import com.bwf.exception.RegistException;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/12 9:33
 * @Copyright 博为峰
 */
public abstract class Account implements Serializable{

    private static final long serialVersionUID = 2830223453264746011L;

    private String cardNo;
    private String password;
    private double balance;

    public Account() {
    }

    public Account(String cardNo, String password, double balance) {
        this.cardNo = cardNo;
        this.password = password;
        this.balance = balance;
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public void save(double money) {
        this.balance += money;
        FileOutputStream fos = null;
        ObjectOutputStream objectOutputStream = null;
        try {
            fos = new FileOutputStream("C:\\Users\\admin\\Desktop\\io\\" + this.cardNo + ".txt");
            objectOutputStream = new ObjectOutputStream(fos);
            objectOutputStream.writeObject(this);
        } catch (IOException e) {
            throw new RuntimeException("存储异常");
        } finally {
            try {
                fos.close();
                objectOutputStream.close();
            } catch (IOException e) {
            }
        }
    }

    public abstract void deposit(double money);
}
